filechooserbutton: Restore to an empty previous selection properly
authorFederico Mena Quintero <federico@gnome.org>
Wed, 13 Feb 2013 17:01:50 +0000 (11:01 -0600)
committerFederico Mena Quintero <federico@gnome.org>
Thu, 14 Feb 2013 00:01:39 +0000 (18:01 -0600)
If no file was originally selected in the GtkFileChooserButton, then its
internal dialog is brought up and cancelled, then we need to restore the
selection back to none.  GtkFileChooser, though, doesn't like to
select a NULL file, so call _unselect_all() in that condition.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
gtk/gtkfilechooserbutton.c

index ba2a445e6a91f7782f0d8f8b0029e6c7f6f9552c..4604cdd15426a846f9665f664a3bfcbeac8b071e 100644 (file)
@@ -2555,6 +2555,17 @@ fs_bookmarks_changed_cb (GtkFileSystem *fs,
   update_combo_box (user_data);
 }
 
+static void
+restore_inactive_selection (GtkFileChooserButton *button)
+{
+  GtkFileChooserButtonPrivate *priv = button->priv;
+
+  if (priv->selection_while_inactive)
+    gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->dialog), priv->selection_while_inactive, NULL);
+  else
+    gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->dialog));
+}
+
 /* Dialog */
 static void
 open_dialog (GtkFileChooserButton *button)
@@ -2589,7 +2600,7 @@ open_dialog (GtkFileChooserButton *button)
       g_signal_handler_block (priv->dialog,
                              priv->dialog_selection_changed_id);
 
-      gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->dialog), priv->selection_while_inactive, NULL);
+      restore_inactive_selection (button);
 
       priv->active = TRUE;
     }
@@ -2772,12 +2783,10 @@ dialog_response_cb (GtkDialog *dialog,
       update_label_and_image (button);
       update_combo_box (button);
     }
-  else if (priv->selection_while_inactive)
+  else
     {
-      gtk_file_chooser_select_file (GTK_FILE_CHOOSER (dialog), priv->selection_while_inactive, NULL);
+      restore_inactive_selection (button);
     }
-  else
-    gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));
 
   if (priv->active)
     {